package com.wk.springframework.context.event;

import com.wk.springframework.beans.factory.config.BeanFactory;
import com.wk.springframework.context.ApplicationEvent;
import com.wk.springframework.context.ApplicationListener;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;

@Slf4j
public class SimpleApplicationEventMulticaster extends AbstractApplicationEventMulticaster{

    public SimpleApplicationEventMulticaster(BeanFactory beanFactory) {
        setBeanFactory(beanFactory);
    }
    @Override
    public void multicastEvent(ApplicationEvent event) {
        Collection<ApplicationListener> applicationListeners = getApplicationListeners(event);
        if (applicationListeners.isEmpty()) {
            log.info("No ApplicationListener for event: {}", event);
            return;
        }
        for (ApplicationListener applicationListener : applicationListeners) {
            applicationListener.onApplicationEvent(event);
        }
    }
}
